//
//  changePassWordViewController.m
//  WHB_logist
//
//  Created by 徐国庆 on 15/12/7.
//  Copyright (c) 2015年 turing. All rights reserved.
//

#import "changePassWordViewController.h"

@interface changePassWordViewController ()<UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate>

@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)NSArray     *array;
@property(nonatomic, strong)UITextField *oldPassWordTF;
@property(nonatomic, strong)UITextField *newsPassWordTF;
@property(nonatomic, strong)UITextField *tureNewPassWordTF;

@property(nonatomic, strong)NSString    *oldPassWordStr;
@property(nonatomic, strong)NSString    *newsPassWordStr;
@property(nonatomic, strong)NSString    *tureNewPassWordStr;

@end

@implementation changePassWordViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.array = [NSArray arrayWithObjects:@"原始密码:", @"   新密码:", @"确认密码:", nil];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navtitle.text = @"登陆密码";
    
    [self initWithView];
    
}

#pragma mark UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *indentifer = @"changePassWordCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifer];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifer];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = [self.array objectAtIndex:indexPath.row];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    
    if (indexPath.row == 0) {
        self.oldPassWordTF = [[UITextField alloc] initWithFrame:CGRectMake(90, 0, kUIScreenWidth - cell.textLabel.frame.size.width, 44)];
        self.oldPassWordTF.delegate = self;
        [self.oldPassWordTF addTarget:self action:@selector(textFieldEditing:) forControlEvents:UIControlEventAllEditingEvents];
        [cell.contentView addSubview:self.oldPassWordTF];
    } else if (indexPath.row == 1){
        self.newsPassWordTF = [[UITextField alloc] initWithFrame:CGRectMake(90, 0, kUIScreenWidth - cell.textLabel.frame.size.width, 44)];
        self.newsPassWordTF.delegate = self;
        [self.newsPassWordTF addTarget:self action:@selector(textFieldEditing:) forControlEvents:UIControlEventAllEditingEvents];
        [cell.contentView addSubview:self.newsPassWordTF];
    } else if (indexPath.row == 2){
        self.tureNewPassWordTF = [[UITextField alloc] initWithFrame:CGRectMake(90, 0, kUIScreenWidth - cell.textLabel.frame.size.width, 44)];
        self.tureNewPassWordTF.delegate = self;
        [self.tureNewPassWordTF addTarget:self action:@selector(textFieldEditing:) forControlEvents:UIControlEventAllEditingEvents];
        [cell.contentView addSubview:self.tureNewPassWordTF];
    }
    
    return cell;
}

#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self closeKeyWord];
    return YES;
}

- (void)textFieldEditing:(UITextField *)textField{
    if (textField == self.oldPassWordTF) {
        self.oldPassWordStr = textField.text;
    } else if (textField == self.newsPassWordTF){
        self.newsPassWordStr = textField.text;
    } else if (textField == self.tureNewPassWordTF){
        self.tureNewPassWordStr = textField.text;
    }
    NSLog(@"%@==%@==%@", self.oldPassWordStr, self.newsPassWordStr, self.tureNewPassWordStr);
}

- (void)footerButtonAction:(UIButton *)button{
    NSLog(@"提交修改");
    
}

- (UIView *)footerView{
    
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth, 40)];
    
    UIButton *footerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    footerButton.frame = CGRectMake(10, 0, kUIScreenWidth - 20, 35);
    footerButton.layer.masksToBounds = YES;
    footerButton.layer.cornerRadius = 5;
    [footerButton setTitle:@"提交修改" forState:UIControlStateNormal];
    footerButton.backgroundColor = [UIColor HexStrWithColor:@"CE0000"];
    [footerButton addTarget:self action:@selector(footerButtonAction:) forControlEvents:UIControlEventTouchDown];
    [bottomView addSubview:footerButton];
    return bottomView;
}


- (void)initWithView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -20, kUIScreenWidth, kUIScreenHeight) style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.tableFooterView = [self footerView];
    [self.view addSubview:self.tableView];
    
    UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeKeyWord)];
    tapGesture.cancelsTouchesInView=NO;//解决自定义tableviewcell与手势冲突
    [self.view addGestureRecognizer:tapGesture];

}

-(void)closeKeyWord
{
    [self.oldPassWordTF resignFirstResponder];
    [self.newsPassWordTF resignFirstResponder];
    [self.tureNewPassWordTF resignFirstResponder];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
